/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.coopeud.vista.eventos;

import edu.coopeud.persistencia.dao.EventoDao;
import edu.coopeud.persistencia.model.Evento;
import java.util.List;

/**
 *
 * @author Alejo
 */
public class VentanaCancelarEvento extends javax.swing.JFrame {

   private List<Evento> eventos ;
   private VentanaAdministrarEventos admin;
    
    public VentanaCancelarEvento() {
        
        super("Cancelar Evento");
        
        initComponents();
        
        this.eventos = EventoDao.getInstanciaEventoDao().obtenerEventos();
        
        System.out.println("obtenerEventos: "+this.eventos );
        
        for (Evento evento : this.eventos) {
            
            cbxEvento.insertItemAt(evento.getnNombreEvento(), eventos.indexOf(evento));
            
        }
                
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblUno = new javax.swing.JLabel();
        cbxEvento = new javax.swing.JComboBox();
        btnCancelarEvt = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        lblUno.setText("Seleccione el Evento a Cancelar");

        btnCancelarEvt.setText("Cancelar Evento");
        btnCancelarEvt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarEvtActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblUno, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(cbxEvento, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(189, 189, 189)
                .addComponent(btnCancelarEvt)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblUno)
                    .addComponent(cbxEvento, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(btnCancelarEvt)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCancelarEvtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarEvtActionPerformed
        Evento evento = this.eventos.get(cbxEvento.getSelectedIndex());
        int respuesta = EventoDao.getInstanciaEventoDao().cancelarEvento(evento);
        System.out.println("cancelarEvento: "+evento.getnNombreEvento()+"; respuesta: "+respuesta);
        
    }//GEN-LAST:event_btnCancelarEvtActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        cerrar();
        getAdmin().setVisible(true);
    }//GEN-LAST:event_formWindowClosing

    public void cerrar(){
        dispose();
    }
    
    public VentanaAdministrarEventos getAdmin(){
        if (admin==null){
            admin=new VentanaAdministrarEventos();
        }
        return admin;
    } 
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelarEvt;
    private javax.swing.JComboBox cbxEvento;
    private javax.swing.JLabel lblUno;
    // End of variables declaration//GEN-END:variables
}
